﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PhoneApp1
{
    public partial class DetailPage : PhoneApplicationPage
    {

        private int _categoryIndex = -1;
        private int _signIndex = -1;

        public DetailPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(DetailPage_Loaded);
        }

        void DetailPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (_categoryIndex != -1 && _signIndex != -1)
            {
                var sign = Model.Data.Categories[_categoryIndex].Signs[_signIndex];
                this.PageTitle.Text = sign.Name;
                this.image1.Source = new BitmapImage(sign.ImageUri);
                this.textBlock1.Text = sign.Description;
            }
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (this.NavigationContext.QueryString.ContainsKey(Constants.CategoryIndex))
            {
                _categoryIndex = int.Parse(this.NavigationContext.QueryString[Constants.CategoryIndex]);
            }
            if (this.NavigationContext.QueryString.ContainsKey(Constants.SignIndex))
            {
                _signIndex = int.Parse(NavigationContext.QueryString[Constants.SignIndex]);
            }
        }
    }
}